package com.yanqu.road.server.timer.player;

import com.yanqu.road.entity.player.PlayerState;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.EarnSpeedModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.executor.GeneralTask;

import java.util.List;

/**
 * 计算玩家赚钱速度和银两
 */
public class PlayerSilverCalcTask extends GeneralTask {

	private static int calcUserDataThreadCount = Runtime.getRuntime().availableProcessors();

	private int index;

	public PlayerSilverCalcTask(int goldIndex){
		this.index = goldIndex;
	}

	@Override
	public void doRun() {
		List<GamePlayer> playerList = GamePlayerMgr.getCopyPlayerList();
		for (GamePlayer player : playerList) {
			if (player.getState() == PlayerState.ONLINE && player.getUserId() % calcUserDataThreadCount == index) {
				player.getModule(EarnSpeedModule.class).scheduleAddSilver(true);
			}
		}
	}
}
